import {homeworkAPI} from '../../api/homeworkAPI'
const FN = require('../../utils/public');
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appHeight: '',
    hwList: [],
    userInfo: {},
    teacherInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.hideShareMenu(); // 禁止分享
    that.initData(1);
    wx.getStorage({
      key: 'wxInfo',
      success(res) {
        var teacherInfo = "teacherInfo.wxinfo";
        that.setData({
          [teacherInfo]: res.data
        })
      },
      fail() {

      },
      complete() {

      }
    })
  },


  /**
   * 初始话数据
   */
  initData: function (p) {
    var that = this;
    homeworkAPI.getStuAllHomework({pageNum:p,
      pageSize: 6}).then(res => {
      if (res.code == '200') {
        if (res.data.list.length == 0) {
          FN.Toast('没有更多数据了')
        } else {
          var resArr = that.data.hwList;
          resArr.push.apply(resArr, res.data.list); //上拉加载
          that.setData({
            hwList: resArr
          })
          console.log(that.data.hwList);
        }
      }
    })
  },

  // 跟读情况
  repeatDetail: function (e) {
    var hwid = e.currentTarget.dataset.homeworkid;
    wx.navigateTo({
      url: '../hwRepeatDetail/hwRepeatDetail?hwid=' + hwid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    page++;
    this.initData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})